package com.yunhe.device.repository.base;

import com.yunhe.device.domain.base.EquipmentAttributes;
import com.yunhe.device.domain.base.DeviceType;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName EquipmentAttributesRepository
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/15 12:40
 * @Version 1.0
 **/
@Repository
public interface EquipmentAttributesRepository extends Neo4jRepository<EquipmentAttributes,Long> {
    EquipmentAttributes findByTitle(String title);

    EquipmentAttributes findByName(String name);

    List<EquipmentAttributes> findByActivityAndType(String activity,String type);

    @Query("match(et:DeviceType{name:{equipName}})-[:HAS_EQUIPATTR]->(ea:EquipmentAttributes{activity:'1'}) where ea.type='01'  return ea order by ea.createTime asc")
    List<EquipmentAttributes> getEquipmentAttributesByEquipTypeName(@Param("equipName") String equipName);

    @Query("match(et:DeviceType)-[:HAS_EQUIPATTR]->(ea:EquipmentAttributes) where ID(ea)={id}  return et ")
    List<DeviceType> findAnlogTypeById(@Param("id") Long id);

    @Query("match(et:DeviceType)-[:HAS_EQUIPATTR]->(ea:EquipmentAttributes) where ID(et)={id}  return ea ")
    List<EquipmentAttributes> getEquipmentAttributesByEquipTypeId(@Param("id") Long id);

    @Query("match(ea:EquipmentAttributes) where ea.name IN {names} return ea")
    List<EquipmentAttributes> findEquipmentAttributesByName(@Param("names") List<String> names);

}
